import time
# from PySide6.QtWidgets import QApplication

def dealExcel(id,person,screenRow,data_sheet,data_row_list,sumSpend,full_end_row,tmp_sheet,png_sheet,png_insert_row_str):
    # logBrowser.append('执行截图')
    # QApplication.processEvents()
    try:
        # logBrowser.append('复制表头')
        data_sheet.range('A1:F1').copy()
        tmp_sheet.range('A1:F1').paste()
        # logBrowser.append('过滤id、person')
        tmp_sheet.range('A1').api.AutoFilter(Field=1, Criteria1=id, Operator=1)
        tmp_sheet.range('F1').api.AutoFilter(Field=6, Criteria1=person, Operator=1)

        data_insert_row = 2
        # logBrowser.append('复制数据')
        for row_index in data_row_list:
            row_index = row_index + 2
            data_sheet.range('A{}:F{}'.format(row_index, row_index)).copy()
            tmp_sheet.range('A{}:F{}'.format(data_insert_row,data_insert_row)).paste()
            data_insert_row += 1
        data_sheet.range('A{}:F{}'.format(full_end_row, full_end_row)).copy()
        tmp_sheet.range('A{}:F{}'.format(screenRow + 2, screenRow + 2)).paste()

        # logBrowser.append('设置单元格颜色')
        #设置单元格颜色，白色
        tmp_sheet.range('A2:F{}'.format(screenRow + 1)).color = (255, 255, 255)
        # logBrowser.append('设置总支出')
        #设置单元格内容
        tmp_sheet.range('E{}'.format(screenRow + 2)).value = sumSpend

        # 4. 获取有内容的 range
        # 5. 复制图片区域
        # logBrowser.append('复制图片')
        # tmp_sheet.Range('A1:F{}'.format(screenRow + 2)).Columns.AutoFit()
        tmp_sheet.range('A1:F{}'.format(screenRow + 2)).copy_picture()

        # logBrowser.append('粘贴图片')
        # 6. 粘贴
        # png_sheet.api.Paste(Destination = png_sheet.api.Range(png_insert_row_str))
        png_sheet.range(png_insert_row_str).paste()

        # logBrowser.append('清除newsheet内容及格式')
        #清除newsheet内容及格式
        tmp_sheet.range('A1:F{}'.format(screenRow + 2)).clear_contents()
        tmp_sheet.clear_formats()

        # logBrowser.append('截图成功')
        # QApplication.processEvents()
    except Exception as e:
        print(e)
        # logBrowser.append('截图失败：{}'.format(e))